#if !defined(ximera_physics_ode_space_hpp)
#define ximera_physics_ode_space_hpp

// -----------------------------------------------------------

#include <ximera/physics/ispace.hpp>
#include <ximera/physics/ientity.hpp>
#include <ximera/physics/ijoint.hpp>
#include <ximera/physics/ode/ode.hpp>
#include <ximera/common/sharedptr.hpp>

#include <vector>

namespace ximera { namespace physics { namespace ode
{
    class World;

	class XIMERA_PLUGIN_API Space : public ISpace
    {
    public:
        Space(World* world, SpaceType type = SpaceType::Simple);
		virtual	~Space();

        virtual SpaceType type() const;

        virtual IWorld* world() const;

        virtual IEntity* createEntity(EntityType type = EntityType::Dynamic);

        virtual UInt32 entityCount() const;
        virtual IEntity* entity(UInt32 index);

        virtual void addEntity(IEntity* entity);
        virtual void removeEntity(IEntity* entity);
        virtual void removeAllEntities();

        virtual IJoint* createJoint(JointType type);

        virtual UInt32 jointCount() const;
        virtual IJoint* joint(UInt32 index);

        virtual void addJoint(IJoint* joint);
        virtual void removeJoint(IJoint* joint);
        virtual void removeAllJoints();

        dSpaceID spaceID() const { return _spaceID; }
        World* odeWorld() const { return _world; }

	private:
        typedef std::vector<IEntity*> EntityContainer;
        typedef std::vector<IJoint*> JointContainer;

		World* _world;
		dSpaceID _spaceID;
		SpaceType _type;

        JointFactory _jointFactory;

		EntityContainer _entities;
		JointContainer _joints;
    };
}}}

// -----------------------------------------------------------

#endif
